package com.jandan.ui.client;

import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.layout.FitLayout;
import com.jandan.ui.model.Word;

public class StrangeWordWindow extends Window {
	public StrangeWordWindow() {
		this.setLayout(new FitLayout());
		this.setTitle("添加生词");
		this.setHeight(350);
		this.setWidth(400);
		this.setCloseAction(Window.CLOSE);
		this.createComponent();
	}

	public StrangeWordWindow(Word word) {
		this.setLayout(new FitLayout());
		this.setTitle("编辑生词" + word.getWordEn());
		
		this.createComponent();

	}

	private void createComponent() {
//		Panel panel = new Panel();
//		panel.setBorder(false);
//		panel.setPaddings(15);

		// create the FormPanel and set the label position to top
//		FormPanel formPanel = new FormPanel();
//		formPanel.setFrame(true);
//		formPanel.setLabelWidth(65);
//		formPanel.setPaddings(5, 5, 5, 0);
////		formPanel.setWidth(600);
//		formPanel.setLabelAlign(Position.RIGHT);
//
////		Panel topPanel = new Panel();
////		topPanel.setLayout(new VerticalLayout(20));
////		topPanel.setLayout(new HorizontalLayout(20));
//		// create first panel and add fields to it
////		Panel wordPanel = new Panel();
////		wordPanel.setLayout(new FormLayout());
//
//		final TextField wordEn = new TextField("英文单词", "wordEn");
//		wordEn.setAllowBlank(false);
////		wordEn.setWidth(200);
//		formPanel.add(wordEn,new AnchorLayoutData("80%"));   
//
//		final TextField phonetics = new TextField("音标", "phonetics");
//		phonetics.setAllowBlank(false);
//		
//		ToolTip tip2 = new ToolTip();   
//        tip2.setTitle("音标输入规则");   
//        tip2.setHtml("Click the X to close me");   
//        tip2.setClosable(true);   
//        tip2.setAutoHide(false);   
//        tip2.applyTo(phonetics);   
//        tip2.setDraggable(true);   
//  
//
//		
////		phonetics.setWidth(120,);
//		phonetics.addClass("phonetics");
//		formPanel.add(phonetics,new AnchorLayoutData("80%"));
//		
//		
//		final TextField wordCn1 = new TextField("中文含义","wordCn1");
//		ToolTip tip3 = new ToolTip();   
//        tip3.setTitle("中文含义输入规则");   
//        tip3.setHtml("对于多个中文含义使用|(竖线)分隔");   
////        tip3.setClosable(true);   
//        tip3.setAutoHide(true);   
//        tip3.applyTo(wordCn1);   
//        tip3.setDraggable(true);   
//
//		wordCn1.setAllowBlank(false);
//	
////		wordCn1.setWidth(200);
//		formPanel.add(wordCn1,new AnchorLayoutData("80%"));
//		
//		final TextArea sentence1 = new TextArea("例句","sentence1");
////		sentence1.setWidth(200);
//		ToolTip tip4 = new ToolTip();   
//        tip4.setTitle("例句含义输入规则");   
//        tip4.setHtml("例句必须与中文含义相对应，每个中文含义只能对应一个例句多个例句用|(竖线)分隔，对于没有对应例句的中文含义，输入none代替。");   
////        tip3.setClosable(true);   
//        tip4.setAutoHide(true);   
//        tip4.applyTo(sentence1);   
//        tip4.setDraggable(true);   
//
//		
//		formPanel.add(sentence1,new AnchorLayoutData("100%"));
//		
////		final TextField wordCn2 = new TextField("中文含义1","wordCn2");
////		wordCn2.setWidth(200);
////		wordPanel.add(wordCn2);
////		
////		final TextArea sentence2 = new TextArea("例句1","sentence2");
////		sentence2.setWidth(200);
////		wordPanel.add(sentence2);
////		
////		TextField wordCn3 = new TextField("中文含义1","wordCn3");
////		wordCn3.setWidth(200);
////		wordPanel.add(wordCn3);
////		
////		TextArea sentence3 = new TextArea("例句1","sentence3");
////		sentence3.setWidth(200);
////		wordPanel.add(sentence3);
////
////		
////		topPanel.add(wordPanel);
////
////		wordCn2.setVisible(false);
////		sentence2.setVisible(false);
////		
////		wordCn3.setVisible(false);
////		sentence3.setVisible(false);
////		
////		
////		Hyperlink link = new Hyperlink();
////		link.setText("添加更多中文含义和例句");
////		topPanel.add(link);
////		
////		link.addClickListener(new ClickListener(){
////			public void onClick(Widget arg0) {
////				// TODO Auto-generated method stub
////				MessageBox.alert("shit");
////				wordCn2.setVisible(true);
////				sentence2.setVisible(true);
////			}
////			
////		});
////		formPanel.add(topPanel);
//		// add a couple of buttons to the form
//		final TextArea explain = new TextArea("解释","explain");
//		formPanel.add(explain,new AnchorLayoutData("100%"));
//		
//		Button save = new Button("保存");
//		Button cancle = new Button("取消");
//		
//		save.addListener(new ButtonListenerAdapter(){
//			@Override
//			public void onClick(Button button, EventObject e) {
//				// TODO Auto-generated method stub
//				String en = wordEn.getText();
//				String ph = phonetics.getText();
//				String cn = wordCn1.getText();
//				String st = sentence1.getText();
//				String ex = explain.getText();
//				
//				Word word = new Word();
////				word.setWordID(en);
//				word.setWordEn(en);
//				word.setPhonetics(ph);
//				
//				String[] cns = cn.split("\\|");
//				List<String> cnsList = new ArrayList<String>();
//				for(int i = 0;i < cns.length;i++){
//					cnsList.add(cns[i]);
//				}
//				word.setWordCn(cnsList);
//				
//				List<String> stsList = new ArrayList<String>();
//				if(st != null){
//					String[] sts = st.split("\\|");
//					for(int i = 0;i < sts.length;i++){
//						stsList.add(sts[i]);
//					}
//				}
//				word.setSentence(stsList);
//				word.setExplain(ex);
//				
//				WordLibServiceAsync service = WordLibService.Util.getInstance();
//				service.addStrangeWord(word, new AsyncCallback<Boolean>(){
//
//					public void onFailure(Throwable caught) {
//						// TODO Auto-generated method stub
//						MessageBox.alert("添加生词错误，请稍候重试!");
//					}
//
//					public void onSuccess(Boolean result) {
//						// TODO Auto-generated method stub
//						boolean r = result.booleanValue();
//						if(r){
//							MessageBox.alert("添加生词成功");
//							closeTheWindow();
//						}
//						else {
//							MessageBox.alert("此单词已在生词本中");
//							closeTheWindow();
//						}
//					}
//				});
//			}
//		});
//		
//		cancle.addListener(new ButtonListenerAdapter(){
//			@Override
//			public void onClick(Button button, EventObject e) {
//				// TODO Auto-generated method stub
////				MessageBox.alert("save");
//				closeTheWindow();
//			}
//		});
//		formPanel.addButton(save);
//		formPanel.addButton(cancle);
//		panel.add(formPanel);
//		
//		this.add(panel);
	}
}
